import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
import {getPopupContainer} from "@vben/utils";
import {getDictOptions} from "#/utils/dict";
import { DictEnum } from '@vben/constants';
import { h } from 'vue';
export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'jobName',
    label: '任务名称',
  },
  {
    component: 'Select',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.SYS_JOB_GROUP),
    },
    fieldName: 'jobGroup',
    label: '任务组名',
  },
  {
    component: 'Select',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.SYS_JOB_STATUS),
    },
    fieldName: 'status',
    label: '任务状态',
  },
];

// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '任务ID',
    field: 'jobId',
  },
  {
    field: 'jobName',
  },
  {
    title: '任务组名',
    field: 'jobGroup',
    slots: { default: 'jobGroup' },
  },
  {
    title: '调用目标字符串',
    field: 'invokeTarget',
  },
  {
    title: 'cron执行表达式',
    field: 'cronExpression',
  },
  {
    title: '状态',
    field: 'status',
    slots: { default: 'status' },
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 180,
  },
];

export const modalSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'jobName',
    label: '任务名称',
    rules: 'required',
  },
  {
    component: 'Select',
    componentProps: {
      allowClear: false,
      options: getDictOptions(DictEnum.SYS_JOB_GROUP),
      getPopupContainer,
    },
    fieldName: 'jobGroup',
    label: '任务组名',
  },
  {
    component: 'Input',
    fieldName: 'invokeTarget',
    label: '调用方法',
    help: 'Bean调用示例：ryTask.ryParams(\'ry\')\n' +
        'Class类调用示例：com.ruoyi.quartz.task.RyTask.ryParams(\'ry\')\n' +
        '参数说明：支持字符串，布尔类型，长整型，浮点型，整型',
    rules: 'required',
  },
  {
    component: 'Input',
    dependencies: {
      // 类型不为按钮时显示
      show: (values) => values.menuType !== 'F',
      triggerFields: ['menuType'],
    },
    // renderComponentContent: ({ formActionType }) => ({
    //   addonAfter: () =>
    //       h(
    //           'a',
    //           {
    //             href: 'javascript:void(0);',
    //           },
    //           '生成表达式'
    //       ),
    // }),
    fieldName: 'cronExpression',
    label: 'cron表达式',
    rules: 'required',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: yesStrategy,
      optionType: 'button',
    },
    defaultValue: '1',
    fieldName: 'configType',
    label: '执行策略',
    rules: 'required',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: yesNoOptions,
      optionType: 'button',
    },
    defaultValue: '0',
    fieldName: 'concurrent',
    label: '是否并发',
    rules: 'required',
  },
];

export const yesNoOptions = [
  { label: '允许', value: '0' },
  { label: '禁止', value: '1' },
];

export const yesStrategy = [
  { label: '立即执行', value: '1' },
  { label: '执行一次', value: '2' },
  { label: '放弃执行', value: '3' }
];


